package com.ruoyi.biz.export;

import com.ruoyi.biz.export.enums.ExportTemplateEnum;
import com.ruoyi.biz.export.executor.AbstractExecutor;
import com.ruoyi.biz.export.vo.ExportVO;
import com.ruoyi.biz.export.vo.ReqVO;
import com.ruoyi.biz.letter.domain.BizCityLetter;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import lombok.SneakyThrows;
import org.springframework.beans.BeanUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * @author Fei.Cong
 * @date 2024-07-17 8:42
 */
@RestController
@RequestMapping("/letter/export")
public class ExportController {

    /**
     * 导出
     */
    @SneakyThrows
    @PreAuthorize("@ss.hasPermi('city:letter:export')")
    @Log(title = "地市信访导出", businessType = BusinessType.EXPORT)
    @PostMapping("/exportData")
    public void exportData(HttpServletResponse response, ExportVO exportVO) {
        AbstractExecutor controllerExecutor = ExportTemplateEnum.getTemplateType(exportVO.getExportType());
        ExportTemplateEnum type = ExportTemplateEnum.getType(exportVO.getExportType());
        BizCityLetter bizCityLetter = new BizCityLetter();
        BeanUtils.copyProperties(exportVO, bizCityLetter);
        ReqVO reqVo = ReqVO.builder()
                .os(response.getOutputStream())
                .billMonth(exportVO.getBillMonth())
                .bizCityLetter(bizCityLetter)
                .clazz(type.getObjClazz())
                .templateEnum(type)
                .build();
        controllerExecutor.execute(reqVo);
    }
}
